package com.riaevolution.themes.facebook
{
    import flash.display.GradientType;
    import flash.display.Graphics;
    
    import mx.skins.Border;
    import mx.utils.ColorUtil;
    
    public class ScrollThumbSkin extends Border
    {
        override public function get measuredWidth():Number
        {
            return 15;
        }
    
        override public function get measuredHeight():Number
        {
            return 11;
        }
        
        override protected function updateDisplayList(w:Number, h:Number):void
        {
            super.updateDisplayList(w, h);
    		
    		var colorDefault:uint = 0x3B5998;
    		//this.parent.parentDocument
    		/* if(this.parent && this.parent.hasOwnProperty("parentDocument")) {
    			var parentCol:uint = this.parent['parentDocument'].getStyle("trackColor");
    			if(!isNaN(parentCol) && parentCol != 0) colorDefault = parentCol;
    		} */
    		
            // User-defined styles.
            var borderColorDark :uint = colorDefault;
            var borderColor:uint = ColorUtil.adjustBrightness(borderColorDark, -50);
            var borderAlphas:Array = [0.5, 1.0];
            var backgroundColor:uint = 0x555555;
            var backgroundAlpha:Number = 0.3;
            
            var hole:Object = null;
            
            graphics.clear();   
            
            // draw fill with alpha = 0.0 to capture mouse events
            drawRoundRect(1, 0, w - 3, h, 0, backgroundColor, 0.0);                       
    
            switch (name)
            {
                default:
                case "thumbUpSkin":
                {
                    // Draw background with low alpha
                    //drawCrossHatch(graphics, w - 3, h, backgroundColor, backgroundAlpha);  
    
                    // border
                    drawRoundRect(0, 1, w   , h - 2, 0, [borderColor, borderColor], borderAlphas,
                        null, GradientType.LINEAR, null, hole);    
    
                    break;
                }
                
                case "thumbOverSkin":
                {
                    // Draw background with low alpha
                    //drawCrossHatch(graphics, w - 3, h, backgroundColor, backgroundAlpha);  
            
                    // border
                   drawRoundRect(0, 1, w  , h - 2, 0, [borderColorDark, borderColorDark], borderAlphas,
                        null, GradientType.LINEAR, null, hole);  
                    
                    break;
                }
                
                case "thumbDownSkin":
                {                
                    // Draw background with higher alpha
                    //drawCrossHatch(graphics, w - 3, h, backgroundColor, 2 * backgroundAlpha);  
    
                    // border
                    drawRoundRect(0, 1, w   , h - 2, 0, [borderColorDark, borderColorDark], borderAlphas,
                        null, GradientType.LINEAR, null, hole);  
                                        
                    break;
                }
                
                case "thumbDisabledSkin":
                {
                    // positioning placeholder
                    drawRoundRect(
                        0, 0, w, h, 0,
                        0xFFFFFF, 0); 
                    
                    // border
                    drawRoundRect(
                        1, 0, w - 3, h, 0,
                        0x999999, 0.5);
                    
                    // fill
                    drawRoundRect(
                        1, 1, w - 4, h - 2, 0,
                        0xFFFFFF, 0.5);
                    
                    break;
                }
            }
            
            // Draw grip.        
            var gripL:Number = Math.floor(w / 2 - 4);
            var gripR:Number = w - gripL;
            var gripH:Number = Math.floor(h/2);
            
            graphics.lineStyle(1, 0xFFFFFF, .7);
            graphics.moveTo(gripL, gripH - 3);
            graphics.lineTo(gripR, gripH - 3);
            graphics.moveTo(gripL, gripH);
            graphics.lineTo(gripR, gripH);
            graphics.moveTo(gripL, gripH + 3);
            graphics.lineTo(gripR, gripH + 3);
        }
    
        /** the cross-hatch pattern here is a bit different from ScrawlUtil.drawCrossHatch() */
        private function drawCrossHatch(g:Graphics, w:int, h:int, color:uint, _alpha:Number):void
        {
            // draw cross-hatch fill
        }
    }
}
